home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / Developer Documentation / Human Interface / Human Interface Q & A / HI Q& A #10 next >
Encoding:
Text File  |  1996-04-26  |  9.1 KB  |  198 lines  |  [ttro/ttxt]

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. Q&A #10
  18. Scripting, Buttons, and Hypertext
  19.  
  20. By the Apple Computer OpenDoc Human Interface Team and Jon Pugh OpenDoc Engineering
  21.  
  22. As published in the January 1996 Apple Directions
  23.  
  24. This time we're going to focus on supporting scripting within OpenDoc. This
  25. article doesn't address all the questions on scripting, so please send us
  26. any others you think of; we'll answer them in future columns.
  27.  
  28. Q: How do you script actions like selecting a menu and other controls (such
  29. as sliders)?
  30.  
  31. A: This might be a good time to briefly mention the different levels of
  32. scripting support. If you want more details on scripting, see Chapter 9 in
  33. the OpenDoc Programmer's Guide.
  34.  
  35. First, a part can be scriptable. To be scriptable, your part editor must
  36. publish a list of its content objects (for example, lines and words in a
  37. text part) and operations (for example, bold in a text part) and then accept
  38. semantic events (for example, "Set Data to Bold"). For your part to be fully
  39. scriptable, semantic events must be able to invoke any action a user might
  40. be able to perform. Someone can then write a script to invoke the particular
  41. user action.
  42.  
  43. The next level of scripting support is for your part to support recording.
  44. If your part is recordable, it can capture the user's actions as a series of
  45. semantic events, convert the actions to scripts, and replay them at a later
  46. time to reenact the actions.
  47.  
  48. The final level of scripting support is to make your part's interface
  49. customizable (sometimes referred to as being "tinkerable"). If your part is
  50. customizable, users can invoke all the actions through scripts, and they can
  51. change the behavior of the operations. To be customizable, the part editor
  52. must be scriptable and must define content objects and operations for
  53. interface elements such as menus and buttons.
  54.  
  55. Getting back to your question, your part's interface must be customizable to
  56. support the actions you mention. We've said in a previous column (Apple
  57. Directions, October 1995) that users may attach a script to a scriptable
  58. part--for example, through the Settings dialog box. A script may have
  59. multiple sections of script code (handlers) for the different operations
  60. whose behavior you want to change. Suppose that you want your part to
  61. support events such as mouseDown, mouseUp, mouseEnter, mouseLeave, and
  62. pickMenuItem; when designing your part editor, you must define event names
  63. for each operation that your editor will support. Before your editor
  64. processes any event, the editor must check with the attached script to see
  65. if it can handle the event. If so, that section of the script is run.
  66.  
  67. If you want to allow users to write scripts that control your part, you
  68. should publish your list of event names in your part's documentation and
  69. 'aete' resource. Because HyperCard uses a set of event names for the common
  70. actions a user might perform, you might want to look at HyperCard events as
  71. examples to follow. By the way, HyperCard uses the subroutine event to
  72. implement many of its events. For more details on subroutines, you may want
  73. to look at the Developer Notes document on the AppleScript CD.
  74.  
  75. Q: What about scripting document-level commands such as Open, Close, and
  76. Print? What do I have to do?
  77.  
  78. A: There are operations that relate to the entire document--for example,
  79. closing, saving, and printing the current document, or opening a different
  80. document. The OpenDoc shell handles three of the four required events (the
  81. fourth, Open Application, does not apply in the OpenDoc environment). Your
  82. part editor can override the definitions of these events. Note that
  83. definitions of these events are slightly different than in today's
  84. applications:
  85.  
  86.    • Quit--close all windows of the document
  87.    • Print--print the active window
  88.    • Open--open the specified document
  89.  
  90. The OpenDoc shell also supports three of the core events, which your editor
  91. may override. The events are
  92.  
  93.    • Close--close the active window
  94.    • Save--save the current document
  95.    • Save As--save a copy of the current document into a new document
  96.  
  97. The OpenDoc shell will first determine if the editor of the root part
  98. implements these commands; otherwise, the shell provides the default
  99. implementation.
  100.  
  101. In addition, if the user wishes to attach a script that is to be executed
  102. for one of these events, they must be attached to the root part of the
  103. document.
  104.  
  105. Q: How should a script identify parts within a document?
  106.  
  107. A: This can be very tricky for any document that can be revised, because
  108. parts need not be named or have unique names. Furthermore, the index of a
  109. part may vary over time, and different parts will have different ways of
  110. indexing their contents. For example, "line 3" is fairly obvious; "circle 3"
  111. is not. Therefore, the only reliable way to refer to a part is by its ID.
  112. Unfortunately, the ID is not a very user-friendly or visible number;
  113. however, the user can always find the ID of a part through the Part Info
  114. dialog box.
  115.  
  116. This problem isn't unique to OpenDoc, or even to AppleScript. There just
  117. doesn't seem to be a great solution to this problem.
  118.  
  119. Q: In a previous column, you said that parts should place their scripts in
  120. the Settings dialog box. Doesn't that force parts to provide some
  121. text-editing capability to edit scripts?
  122.  
  123. A: Yes--to allow users to edit the script, your part needs to provide some
  124. mechanism for viewing and editing the script. For a text-based language,
  125. that means you need to support text editing. (Remember that some script
  126. languages may have a representation other than text.) The text editor you
  127. provide can just be a simple multiline edit control. For the future, we are
  128. looking at providing a scripting service that parts could use.
  129.  
  130. Q: I want to create a "button" that really is an embedded graphic in a
  131. container part--like having a picture in a HyperCard stack. When the user
  132. clicks the "button," the container part will run some script. In other
  133. words, the graphic part does not support scripting, but its container
  134. provides the scripting for the embedded part and gives it button-like
  135. behavior. Any suggestions?
  136.  
  137. A: The basic rule in OpenDoc is that a click goes through to the smallest
  138. part containing the mouse pointer. So, if the user clicks on the graphic,
  139. that part would get the click. But in your example you want the container to
  140. get the click and handle it. To do this you need to "fake out" the embedded
  141. part so that it doesn't get the click, but the container does.
  142.  
  143. There is one easy way to get around this problem. If a part is "bundled,"
  144. then it doesn't get the click--its container does. So, the container could
  145. always set the bundled checkbox (in the Part Info dialog box) for all parts
  146. that are embedded within that container.
  147.  
  148. Whenever the user clicks the graphic part, the container part would get the
  149. click, determine which "button" was clicked, and then run the appropriate
  150. script.
  151.  
  152. This all makes sense when the part is in "run" mode. However, you need to
  153. allow the user to edit the buttons as well. If you have "run" and "edit"
  154. modes, you should turn the bundle property off--otherwise, the user can't
  155. edit the picture of the button.
  156.  
  157. Important: Our guidelines recommend that the user should be the only one who
  158. turns the bundled checkbox on or off. But this example is a case in which
  159. the container part could set the bundle property.
  160.  
  161. Q: How does one avoid modes when editing buttons?
  162.  
  163. A: Modes aren't always a bad thing--we work in different modes all the time.
  164. Modes are bad when they aren't clearly visible. So, a mode for editing a
  165. script, editing the name of a button, or resizing a part should be clearly
  166. distinct from other modes in which the user could be working.
  167.  
  168. Attributes such as button name, size, and color are properties of the
  169. button, and you can place them in the Settings dialog box. Even though
  170. setting attributes is a mode, the mode is clearly visible and distinct.
  171.  
  172. Sometimes your users may need "edit" and "run" modes. For example, imagine
  173. using a part builder to make frequent and numerous property changes. If the
  174. part required you to bring up the Settings dialog box every time you wanted
  175. to add or change a part, after awhile you'd probably want an easier and
  176. faster way to enter these changes directly--an "edit" mode. These builder
  177. applications really need the two modes, because the modes really reflect two
  178. different user tasks. They are long-term modes, and as long as they are
  179. clearly visible and distinct from one another, using them should be clear to
  180. the user.
  181.  
  182. Q: How is hypertext achieved in OpenDoc? I see a couple of ways to do this:
  183. Embed a button in the text part or make hypertext a "style." Which method
  184. would you suggest?
  185.  
  186. A: In the 1.0 release of OpenDoc, we have no specific support for hypertext
  187. links. We know this is an important issue and plan to work on it for a
  188. future release. Right now, any approach will have the same major problem:
  189. namely, OpenDoc does not provide any mechanism to display any destination of
  190. a hypertext link smaller than a part. For example, there is no way to create
  191. a link to a particular paragraph in a text part, or a particular portion of
  192. a picture.
  193.  
  194. We are interested in hearing any suggestions you have.
  195. __________________________________________________________
  196.  
  197. Copyright (c) 1995 by Apple Computer, Inc. All Rights Reserved.
  198.